﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using StoragePeriod.IDAL.StorageForecast;
using StoragePeriod.DALFactory;
using StoragePeriod.Model.StorageForecast;
using System.Data;

namespace StoragePeriod.BLL.StorageForecast
{
    /// <summary>
    /// 指标类型操作，包括其他类型
    /// </summary>
    public partial class T_RawMaterialType
    {
        I_RawMaterialType dal = new DataAccess<I_RawMaterialType>().CreateInstance("StorageForecast.D_RawMaterialType");


        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int id)
        {
            return dal.Exists(id);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(E_RawMaterialType model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(E_RawMaterialType model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int id)
        {

            return dal.Delete(id);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string idlist)
        {
            return dal.DeleteList(idlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public E_RawMaterialType GetModel(int id)
        {

            return dal.GetModel(id);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<E_RawMaterialType> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<E_RawMaterialType> DataTableToList(DataTable dt)
        {
            List<E_RawMaterialType> modelList = new List<E_RawMaterialType>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                E_RawMaterialType model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new E_RawMaterialType();
                    if (dt.Rows[n]["id"].ToString() != "")
                    {
                        model.id = int.Parse(dt.Rows[n]["id"].ToString());
                    }
                    model.TypeName = dt.Rows[n]["TypeName"].ToString();
                    if (dt.Rows[n]["ParentId"].ToString() != "")
                    {
                        model.ParentId = int.Parse(dt.Rows[n]["ParentId"].ToString());
                    }
                    model.temp1 = dt.Rows[n]["temp1"].ToString();
                    model.temp2 = dt.Rows[n]["temp2"].ToString();
                    if (dt.Rows[n]["TypeInfoid"].ToString() != "")
                    {
                        model.TypeInfoid = int.Parse(dt.Rows[n]["TypeInfoid"].ToString());
                    }
                    model.RawTypePath = dt.Rows[n]["RawTypePath"].ToString();
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

    }
}
